package com.aneliya.command.loginDialog;

import com.aneliya.framework.mvc.Facade;
import com.aneliya.framework.mvc.controller.ICommand;
import com.aneliya.framework.mvc.controller.MVCEvent;
import com.aneliya.mediator.LoginDialogMediator;
import com.aneliya.proxy.MessagesProxy;
import com.aneliya.proxy.OnlineUsersProxy;
import com.aneliya.proxy.UserProxy;

public class LoginSuccessfulCommand implements ICommand {

	public void execute(MVCEvent event) {
		try {
			LoginDialogMediator loginDialogMediator = 
				(LoginDialogMediator)Facade.getInstance().retrieveMediator("LoginDialogMediator");
			loginDialogMediator.close();
			
			MessagesProxy messagesProxy = 
				(MessagesProxy) Facade.getInstance().retrieveProxy("MessagesProxy");
			messagesProxy.retrieveHistory();
			
			UserProxy userProxy = (UserProxy) Facade.getInstance().retrieveProxy("UserProxy");
			OnlineUsersProxy onlineUsersProxy = 
				(OnlineUsersProxy) Facade.getInstance().retrieveProxy("OnlineUsersProxy");
			onlineUsersProxy.addOnlineUser(userProxy.getAuthenticatedUser().getUsername());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
